package com.msu.nava.adpter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.msu.nava.R;
import com.msu.nava.modle.Medicine;

import java.util.List;

public class MedicineAdapter extends ArrayAdapter<Medicine> {

  private int resourceId;

  public MedicineAdapter(@NonNull Context context, int resource, @NonNull List<Medicine> objects) {
    super(context, resource, objects);
    resourceId = resource;
  }

  @NonNull
  @Override
  public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
    Medicine medicine = getItem(position);
    View view = LayoutInflater.from(getContext())
      .inflate(resourceId,parent,false);
    TextView tvmane  = (TextView) view.findViewById(R.id.tvmname);
    TextView tveffect  = (TextView) view.findViewById(R.id.tveffect);
    TextView tvcomposition  = (TextView) view.findViewById(R.id.tvcomposition);
    TextView tvprice = (TextView) view.findViewById(R.id.tvprice);

    tvmane.setText(medicine.getMedicineName());
    tveffect.setText("功效主治:\n"+medicine.getEffect());
    tvcomposition.setText("组成:\n"+medicine.getComposition());
    tvprice.setText("参考价格: ¥ "+medicine.getPrice());

    return view;
  }

  @Nullable
  @Override
  public Medicine getItem(int position) {
    return super.getItem(position);
  }
}
